package com.freedom.sql.jdbc.pool.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.freedom.sql.jdbc.utils.MyJsonProperties;

public class ExecutorPool {
	@SuppressWarnings("unused")
	private static final Logger logger = LogManager.getLogger(ExecutorPool.class);

	private ExecutorPool() {
	}

	// 单例模式
	private static ExecutorService instance = null;
	static {
		int consumerWorkerNumber = MyJsonProperties.getInstance().getConsumerWorker();
		instance = new ThreadPoolExecutor(consumerWorkerNumber, consumerWorkerNumber, //
				0L, TimeUnit.MILLISECONDS, //
				new LinkedBlockingQueue<Runnable>(), //
				new DefaultThreadFactory("ExecutorPool-counter"));
	}

	public static ExecutorService getInstance() {
		return instance;
	}
}
